#文字列要素(配列)のアクセス
#N.SUN 2022/11/24

# coding:utf-8
# Strings are Arrays
"""
Like many other popular programming languages, 
strings in Python are arrays of bytes representing unicode characters.

However, Python does not have a character data type, 
a single character is simply a string with a length of 1.

Square brackets can be used to access elements of the string.
"""
# To get the length of a string, use the len() function.
a = "Hello, World!"
b = "秋風の石を拾ふ"

print(a)
print(len(a), a[0], a[-1], a[4])


input("\n Enterで次へ\n")

# Since strings are arrays, we can loop through the characters in a string, with a for loop.

str = ""
for i in range(0,len(b),1):
  str += b[i] 
print(str+"\n")

#There is no built-in reverse function in Python's str object.
#a function of string reverse defined as bellow
def strReverse(b):
  str = ""
  for i in range(0,len(b),1):
    str = b[i] + str
  return str

print(strReverse(b))  

input("\n Enterで次へ\n")
  
# check a string using in
txt = "The best things in life are free!"
print("free" in txt)

if "free" in txt:
  print("Yes, 'free' is present.")
  
# Check if NOT
print("expensive" not in txt)

if "expensive" not in txt:
  print("No, 'expensive' is NOT present.")